package com.etymgiko.lyricshere.web.admin.song;

import org.springframework.web.servlet.mvc.AbstractController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.etymgiko.lyricshere.model.Artist;
import com.etymgiko.lyricshere.model.Song;
import com.etymgiko.lyricshere.manager.ArtistManager;
import com.etymgiko.lyricshere.manager.SongManager;

/**
 *
 * @author Ivan Holub
 */
public class SongDetailsController extends AbstractController {

    private String view;

    private ArtistManager artistManager;

    private SongManager songManager;

    public void setSongManager(SongManager songManager) {
        this.songManager = songManager;
    }

    public void setView(String view) {
        this.view = view;
    }

    public void setArtistManager(ArtistManager artistManager) {
        this.artistManager = artistManager;
    }

    protected ModelAndView handleRequestInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
        String id = httpServletRequest.getParameter("id");
        Song song = songManager.getSong(Long.valueOf(id));
        Artist artist = artistManager.getArtist(song.getArtistId());
        ModelAndView mav = new ModelAndView(view);
        mav.addObject("artist", artist);
        mav.addObject("song", song);
        return mav;
    }
}